package com.lly.songhigh.view;

import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lly.songhigh.R;

/**
 * Created by 李新伟 on 15/10/28.
 */


public class PublishSelectPicPopupWindow extends PopupWindow {
    private View mMenuView;
    private TextView pw_collection, pw_download, pw_share, pw_singer, pw_album, pw_song_info;
    private RelativeLayout alpha_layout1;
    public PublishSelectPicPopupWindow(Activity context,View.OnClickListener itemsOnClick, View view,
                                       RelativeLayout alpha_layout) {
        super(context);
        mMenuView = view;
        alpha_layout1 = alpha_layout;
        pw_collection = (TextView) mMenuView.findViewById(R.id.pw_collection);
        pw_download = (TextView) mMenuView.findViewById(R.id.pw_download);
        pw_share = (TextView) mMenuView.findViewById(R.id.pw_share);
        pw_singer = (TextView) mMenuView.findViewById(R.id.pw_singer);
        pw_album = (TextView) mMenuView.findViewById(R.id.pw_album);
        pw_song_info = (TextView) mMenuView.findViewById(R.id.pw_song_info);
        pw_collection.setOnClickListener(itemsOnClick);
        pw_download.setOnClickListener(itemsOnClick);
        pw_share.setOnClickListener(itemsOnClick);
        pw_singer.setOnClickListener(itemsOnClick);
        pw_album.setOnClickListener(itemsOnClick);

        //设置SelectPicPopupWindow的View
        this.setContentView(mMenuView);
        //设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        //设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        //设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        this.setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss() {
                alpha_layout1.setVisibility(View.GONE);
            }
        });
        //设置SelectPicPopupWindow弹出窗体动画效果
        this.setAnimationStyle(R.style.PWMenuAnim);
        //实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0xffffffff);
        //设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);
        //mMenuView添加OnTouchListener监听判断获取触屏位置如果在选择框外面则销毁弹出框
//        mMenuView.setOnTouchListener(this);
//        mMenuView.setOnTouchListener(new View.OnTouchListener() {
//            public boolean onTouch(View v, MotionEvent event) {
//
//                int height = mMenuView.findViewById(R.id.pop_layout).getTop();
//                int y=(int) event.getY();
//                if(event.getAction()== MotionEvent.ACTION_UP){
//                    if(y<height){
//                        dismiss();
//                        alpha_layout.setVisibility(View.GONE);
//                    }
//                }
//                return true;
//            }
//        });

    }

//    @Override
//    public boolean onTouch(View v, MotionEvent event) {
//        int height = mMenuView.findViewById(R.id.pop_layout).getTop();
//                int y=(int) event.getY();
//                if(event.getAction()== MotionEvent.ACTION_UP){
//                    if(y<height){
//                        Log.i("qiqi", "xiaoshi");
//                        alpha_layout.setVisibility(View.GONE);
//                        dismiss();
//                    }
//                }
//        return true;
//    }
}
